package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.groupseven.happycampus.common.pojo.Athletes;
import com.groupseven.happycampus.common.result.LayuiPageVo;
import com.groupseven.happycampus.common.vo.BarVo;
import com.groupseven.happycampus.common.vo.PieVo;
import com.groupseven.happycampus.mapper.AthletesMapper;
import com.groupseven.happycampus.service.AthletesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

@Service("/athletesService")
public class AthletesServiceImpl implements AthletesService {


    /**
     * 分页以及模糊查询所有运动员信息
     */

    @Autowired
    public AthletesMapper athletesMapper;

    @Override
    public List<Athletes> findAll() {
        return athletesMapper.findAll();
    }

    @Override
    public LayuiPageVo<Athletes> selectAthletes(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");
        PageHelper.startPage(page,limit);

        List<Athletes> hospitalList = athletesMapper.selectAthletes(params);

        PageInfo<Athletes> athletesPageInfo = new PageInfo<>(hospitalList);

        LayuiPageVo<Athletes> athletesLayuiPageVo = new LayuiPageVo<>();
        athletesLayuiPageVo.setCode(0);
        athletesLayuiPageVo.setMsg("分页列表数据");
        athletesLayuiPageVo.setCount((int) athletesPageInfo.getTotal());
        athletesLayuiPageVo.setData(athletesPageInfo.getList());
        return athletesLayuiPageVo;
    }



    /**
     * 添加运动员信息
     * @param athletes
     * @return
     */

    @Override
    public int addAthletes(Athletes athletes) {
        int i = athletesMapper.addAthletes(athletes);
        return i;
    }


    /**
     * 根据id删除运动员信息
     * @param id
     * @return
     */
    @Override
    public int deleteAthletesById(Integer id) {
        return athletesMapper.deleteAthletesById(id);
    }


    /**
     * 批量删除运动员信息
     * @param ids
     * @return
     */
    @Override
    public int deleteAthletesByIds(String ids) {
        String[] arrId = ids.split(",");
        return athletesMapper.deleteAthletesByIds(arrId);
    }



    /**
     * 修改运动员信息
     * @param athletes
     * @return
     */

    @Override
    public int updateAthletes(Athletes athletes) {
        return athletesMapper.updateAthletes(athletes);
    }


    /**
     * 竞赛柱状信息图
     * @return
     */
    @Override
    public List<BarVo> sexBarData() {
        List<BarVo> list = athletesMapper.sexBarData();
        return list;
    }

    /**
     * 竞赛项目饼状信息图
     * @return
     */
    @Override
    public List<PieVo> sexPieData() {
        List<PieVo> list = athletesMapper.sexPieData();
        return list;
    }


}
